{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# TDPF: sensitivity of parameters\n",
    "\n",
    "This tutorial adds more detail to the tutorial about Temperature Dependent Power Flow (TDPF) by exploring the influence of different input parameters. The method, plots and parameter variations are based on the following paper:\n",
    "\n",
    "B. Ngoko, H. Sugihara and T. Funaki, \"A Temperature Dependent Power Flow Model Considering Overhead Transmission Line Conductor Thermal Inertia Characteristics,\" 2019 IEEE International Conference on Environment and Electrical Engineering and 2019 IEEE Industrial and Commercial Power Systems Europe (EEEIC / I&CPS Europe), 2019, pp. 1-6, doi: 10.1109/EEEIC.2019.8783234."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "import pandas as pd\n",
    "import matplotlib.pyplot as plt\n",
    "import numpy as np\n",
    "\n",
    "from pandapower.pf.create_jacobian_tdpf import calc_a0_a1_a2_tau, calc_T_ngoko"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# conductor data\n",
    "t_air = 40\n",
    "t_max = 90\n",
    "t_ref = 25\n",
    "r_ref_ohm_per_m = 0.1824e-3\n",
    "conductor_outer_diameter_m = 18.2e-3\n",
    "v_m_per_s = 0.5\n",
    "wind_angle_degree = 45\n",
    "s_w_per_square_meter = 1000\n",
    "alpha = 0.004\n",
    "solar_absorptivity = emissivity = 0.5\n",
    "mc_joule_per_m_k = 525"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Wind speed\n",
    "\n",
    "First, we calculate the overhead line temperature depending on the current that is flowing through the line for three different wind speed scenarios."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "v_m_per_s = 0.5\n",
    "a0, a1, a2, tau = calc_a0_a1_a2_tau(t_air, t_max, t_ref, r_ref_ohm_per_m,\n",
    "                                    conductor_outer_diameter_m, mc_joule_per_m_k,\n",
    "                                    v_m_per_s, wind_angle_degree, s_w_per_square_meter)\n",
    "\n",
    "t_05 = [calc_T_ngoko(i**2, a0, a1, a2, None, None, None) for i in range(601)]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "v_m_per_s = 2\n",
    "a0, a1, a2, tau = calc_a0_a1_a2_tau(t_air, t_max, t_ref, r_ref_ohm_per_m,\n",
    "                                    conductor_outer_diameter_m, mc_joule_per_m_k,\n",
    "                                    v_m_per_s, wind_angle_degree, s_w_per_square_meter)\n",
    "\n",
    "t_2 = [calc_T_ngoko(i**2, a0, a1, a2, None, None, None) for i in range(601)]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "v_m_per_s = 5\n",
    "a0, a1, a2, tau = calc_a0_a1_a2_tau(t_air, t_max, t_ref, r_ref_ohm_per_m,\n",
    "                                    conductor_outer_diameter_m, mc_joule_per_m_k,\n",
    "                                    v_m_per_s, wind_angle_degree, s_w_per_square_meter)\n",
    "\n",
    "t_5 = [calc_T_ngoko(i**2, a0, a1, a2, None, None, None) for i in range(601)]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "y_label = 'Line temperature (°C)'\n",
    "x_label = 'Current (A)'\n",
    "ax=plt.subplot()\n",
    "ax.plot(np.vstack([t_05, t_2, t_5]).T, label=[\"0.5 m/s\", \"2 m/s\", \"5 m/s\"])\n",
    "ax.grid(True)\n",
    "ax.set_ylabel(y_label)\n",
    "ax.set_xlabel(x_label)\n",
    "ax.legend()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Wind speed has a very high effect on the calculation results. For example, at 300 A the impact of the wind speed between 0.5 m/s and 5 m/s corresponds to a difference in overhead line temperature of just below 50 °C vs. about 65~°C. For the maximum value of 600 A the effect of this parameter is even higher: about 65 °C vs. over 110 °C. The cooling effect increases exponentially with the increase of the line current."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Air temperature\n",
    "\n",
    "Here we specify three different scenarios for the air temperature."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "v_m_per_s = 0.5\n",
    "t_air = 0\n",
    "a0, a1, a2, tau = calc_a0_a1_a2_tau(t_air, t_max, t_ref, r_ref_ohm_per_m,\n",
    "                                    conductor_outer_diameter_m, mc_joule_per_m_k,\n",
    "                                    v_m_per_s, wind_angle_degree, s_w_per_square_meter)\n",
    "\n",
    "t_0 = [calc_T_ngoko(i**2, a0, a1, a2, None, None, None) for i in range(601)]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "t_air = 20\n",
    "a0, a1, a2, tau = calc_a0_a1_a2_tau(t_air, t_max, t_ref, r_ref_ohm_per_m,\n",
    "                                    conductor_outer_diameter_m, mc_joule_per_m_k,\n",
    "                                    v_m_per_s, wind_angle_degree, s_w_per_square_meter)\n",
    "\n",
    "t_20 = [calc_T_ngoko(i**2, a0, a1, a2, None, None, None) for i in range(601)]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "t_air = 40\n",
    "a0, a1, a2, tau = calc_a0_a1_a2_tau(t_air, t_max, t_ref, r_ref_ohm_per_m,\n",
    "                                    conductor_outer_diameter_m, mc_joule_per_m_k,\n",
    "                                    v_m_per_s, wind_angle_degree, s_w_per_square_meter)\n",
    "\n",
    "t_40 = [calc_T_ngoko(i**2, a0, a1, a2, None, None, None) for i in range(601)]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "ax=plt.subplot()\n",
    "ax.plot(np.vstack([t_0, t_20, t_40]).T, label=[\"0 °C\", \"20 °C\", \"40 °C\"])\n",
    "ax.grid(True)\n",
    "ax.set_ylabel(y_label)\n",
    "ax.set_xlabel(x_label)\n",
    "ax.legend()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "The air temperature has a high impact on the overhead line temperature. The cooling effect appears to remain constant with the change of the line current."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Wind Direction\n",
    "\n",
    "We specify three different scenarios for the wind angle of attack."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "v_m_per_s = 0.5\n",
    "wind_angle_degree = 0\n",
    "a0, a1, a2, tau = calc_a0_a1_a2_tau(t_air, t_max, t_ref, r_ref_ohm_per_m,\n",
    "                                    conductor_outer_diameter_m, mc_joule_per_m_k,\n",
    "                                    v_m_per_s, wind_angle_degree, s_w_per_square_meter)\n",
    "\n",
    "t_0 = [calc_T_ngoko(i**2, a0, a1, a2, None, None, None) for i in range(601)]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "wind_angle_degree = 45\n",
    "a0, a1, a2, tau = calc_a0_a1_a2_tau(t_air, t_max, t_ref, r_ref_ohm_per_m,\n",
    "                                    conductor_outer_diameter_m, mc_joule_per_m_k,\n",
    "                                    v_m_per_s, wind_angle_degree, s_w_per_square_meter)\n",
    "\n",
    "t_45 = [calc_T_ngoko(i**2, a0, a1, a2, None, None, None) for i in range(601)]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "wind_angle_degree = 90\n",
    "a0, a1, a2, tau = calc_a0_a1_a2_tau(t_air, t_max, t_ref, r_ref_ohm_per_m,\n",
    "                                    conductor_outer_diameter_m, mc_joule_per_m_k,\n",
    "                                    v_m_per_s, wind_angle_degree, s_w_per_square_meter)\n",
    "\n",
    "t_90 = [calc_T_ngoko(i**2, a0, a1, a2, None, None, None) for i in range(601)]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "ax=plt.subplot()\n",
    "ax.plot(np.vstack([t_0, t_45, t_90]).T, label=[\"0 °\", \"45 °\", \"90 °\"])\n",
    "ax.grid(True)\n",
    "ax.set_ylabel(y_label)\n",
    "ax.set_xlabel(x_label)\n",
    "ax.legend()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Wind direction has a very high impact on the result. The highest cooling effect is observed with the wind angle of 90 °C. The impact of the wind angle increases exponentially with the increase in the line current."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Solar Radiation"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "v_m_per_s = 0.5\n",
    "wind_angle_degree = 45\n",
    "s_w_per_square_meter = 0\n",
    "a0, a1, a2, tau = calc_a0_a1_a2_tau(t_air, t_max, t_ref, r_ref_ohm_per_m,\n",
    "                                    conductor_outer_diameter_m, mc_joule_per_m_k,\n",
    "                                    v_m_per_s, wind_angle_degree, s_w_per_square_meter)\n",
    "\n",
    "t_0 = [calc_T_ngoko(i**2, a0, a1, a2, None, None, None) for i in range(601)]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "s_w_per_square_meter = 500\n",
    "a0, a1, a2, tau = calc_a0_a1_a2_tau(t_air, t_max, t_ref, r_ref_ohm_per_m,\n",
    "                                    conductor_outer_diameter_m, mc_joule_per_m_k,\n",
    "                                    v_m_per_s, wind_angle_degree, s_w_per_square_meter)\n",
    "\n",
    "t_500 = [calc_T_ngoko(i**2, a0, a1, a2, None, None, None) for i in range(601)]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "s_w_per_square_meter = 1000\n",
    "a0, a1, a2, tau = calc_a0_a1_a2_tau(t_air, t_max, t_ref, r_ref_ohm_per_m,\n",
    "                                    conductor_outer_diameter_m, mc_joule_per_m_k,\n",
    "                                    v_m_per_s, wind_angle_degree, s_w_per_square_meter)\n",
    "\n",
    "t_1000 = [calc_T_ngoko(i**2, a0, a1, a2, None, None, None) for i in range(601)]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "ax=plt.subplot()\n",
    "ax.plot(np.vstack([t_0, t_500, t_1000]).T, label=[\"0 W/m²\", \"500 W/m²\", \"1000 W/m²\"])\n",
    "ax.grid(True)\n",
    "ax.set_ylabel(y_label)\n",
    "ax.set_xlabel(x_label)\n",
    "ax.legend()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "The impact of the solar radiation appears to be lower than one of the other weather parameters, and is even reduced slightly at higher currents. It should be acceptable in practice to use assumptions for the solar radiation if the exact data are not available."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Conclusion\n",
    "\n",
    "The wind speed, ambient air temperature and the wind angle of attack are the most relevant parameters."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Thermal inertia\n",
    "\n",
    "The following example demonstrates the thermal inertia effect with a current surge from 250 A to 450 A, starting with the steady-state line temperature."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "t_air = 40\n",
    "t_max = 90\n",
    "t_ref = 20\n",
    "r_ref_ohm_per_m = 0.1824e-3\n",
    "conductor_outer_diameter_m = 18.2e-3\n",
    "v_m_per_s = 0.5\n",
    "wind_angle_degree = 45\n",
    "s_w_per_square_meter = 1000\n",
    "alpha = 0.004\n",
    "solar_absorptivity = emissivity = 0.5\n",
    "mc_joule_per_m_k = 525\n",
    "\n",
    "a0, a1, a2, tau = calc_a0_a1_a2_tau(t_air, t_max, t_ref, r_ref_ohm_per_m,\n",
    "                                    conductor_outer_diameter_m, mc_joule_per_m_k,\n",
    "                                    v_m_per_s, wind_angle_degree, s_w_per_square_meter)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "t_start = calc_T_ngoko(250**2, a0, a1, a2, None, None, None)\n",
    "t = [calc_T_ngoko(450**2, a0, a1, a2, t_min * 60, t_start, tau) for t_min in range(41)]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "ax=plt.subplot()\n",
    "ax.plot(t)\n",
    "ax.grid(True)\n",
    "ax.set_ylim([55, 85])\n",
    "ax.set_ylabel('Line temperature (C)')\n",
    "ax.set_xlabel('Time delay (min)');"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "The thermal inertia behavior demonstrates that there is a delay from a step change of current until the new steady state temperature is established. The majority of the temperature increase happens in the first 15 min. The thermal inertia consideration is useful for analyzing contingencies and evaluating preventive and curative grid operation strategies."
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
